package com.hw.one.collect.config;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * Copyright 2017 汉威.智慧环保事业部. Created by 李亚坤 on 2017/05/17 10:27.
 */
public class ConditionConfig {

	private static String zjfivemin = "/config/zjfivemin.properties";

	private static String xinxiang = "/config/xinxiang.properties";

	private static String anyang = "/config/anyang.properties";

	private static String auth = "/auth.properties";

	private static String modbusPath = "/config/modbus.properties";

	public static final String modbus = "modbus";

	private static String fileUploadPath = "/config/fileupload.properties";

	public static final String fileUpload = "fileUpload";

	private static String ionSoupPath = "/config/ionSoup.properties";

	public static final String ionSoup = "ionsoup";
	private static String collectCommonPath = "/config/collectcommon.properties";

	public static final String collectCommon = "collectcommon";

	private static final String ocecPath = "/config/ocec.properties";
	public static final String ocec = "ocec";

	private static Properties properties = new Properties();

	private static ConditionConfig conditionConfig;

	private static void initConfig(String configPath) {
		InputStream is = ConditionConfig.class.getResourceAsStream(configPath);
		try {
			if (is != null) {
				properties.load(is);
			}
		} catch (IOException e) {

		} finally {
			if (is != null) {
				try {
					is.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}

	/**
	 * 通过key获取value
	 * 
	 * @return
	 */
	public static String get(String key, String config) {
		if ("zjfivemin".equals(config)) {
			initConfig(zjfivemin);
		} else if ("xinxiang".equals(config)) {
			initConfig(xinxiang);
		} else if ("anyang".equals(config)) {
			initConfig(anyang);
		} else if ("auth".equals(config)) {
			initConfig(auth);
		} else if (modbus.equals(config)) {
			initConfig(modbusPath);
		} else if (fileUpload.equals(config)) {
			initConfig(fileUploadPath);
		} else if (ionSoup.equals(config)) {
			initConfig(ionSoupPath);
		} else if (collectCommon.equals(config)) {
			initConfig(collectCommonPath);
		} else if (ocec.equals(config)) {
			initConfig(ocecPath);
		}
		String value = properties.getProperty(key);
		return value;
	}

}
